package org.uni_hi.muus.server;

import java.io.IOException;

import javax.microedition.io.Connector;
import javax.microedition.io.SocketConnection;


/**
 * MIDlet working as simple personal WebServer.
 * Currently this serves simple HTTP GET operation.
 *
 * @author Swen Jung
 * @version 0.0.15
 */

public class WebServer extends Server{
	
	private static String PORT=null;
		
	/**
	 * Default constructor.
	 * @throws IOException 
	 */
	public WebServer(String port) throws IOException {
		super("socket://:"+port,Connector.READ_WRITE,true);
		WebServer.PORT=port;
	}
	
	public static String getServerAddress(){
		return "http://localhost:"+WebServer.PORT+"/";
	}
	
	protected void openAndAccept() throws IOException{
		SocketConnection sc = (SocketConnection)_scn.acceptAndOpen();
		sc.setSocketOption(SocketConnection.KEEPALIVE, 0);
		sc.setSocketOption(SocketConnection.LINGER, 30);
		// service the connection in a separate thread
		RequestHandler rh = new RequestHandler(sc);
	}
}